package com.swordget.service.facade.impl;

import com.swordget.entity.TableDesign;
import com.swordget.service.ImportDeleteService;
import com.swordget.service.ImportExportService;
import com.swordget.service.SwitchingDataSourcesService;
import com.swordget.service.TableManagerService;
import com.swordget.service.facade.ImportExportFacadeServcie;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Objects;

@Service
public class ImportExportFacadeServcieImpl implements ImportExportFacadeServcie {
    @Autowired
    private ImportDeleteService importDeleteService;

    @Autowired
    private ImportExportService importExportServcie;

    @Autowired
    private TableManagerService tableManagerService;

    @Override
    @Transactional
    public void resolveFile(String template, String tableId, String fileNum, String loginId, String orgId, String templateImport) {


        TableDesign tableDesign = tableManagerService.flinOne(tableId);

        String dataSourceId = "";
        if (Objects.nonNull(tableDesign)) {
            dataSourceId = tableDesign.getDataSourceId();
        }

        if("importCover".equals(templateImport)){
            //删除
            importDeleteService.deleteImport(loginId,tableId, dataSourceId);
        }
        importExportServcie.resolveFile(template, tableId, fileNum, loginId, orgId, dataSourceId);
    }
}
